﻿using AutoMapper;
using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    /// <summary>
    /// 入库服务实现层
    /// </summary>
    public class StorageApplication : BaseApplication<StockIn>, IStorageApplication
    {
        private readonly IStorageRepository _storageRepository;
        public StorageApplication(IStorageRepository storageRepository) : base(storageRepository)
        {
            _storageRepository = storageRepository;
        }

        /// <summary>
        /// 入库添加
        /// </summary>
        /// <param name="stockIn"></param>
        /// <returns></returns>
        public APIResult<StockInDTO> AddStockIn(StockInDTO stockIn)
        {
            APIResult<StockInDTO> result = new APIResult<StockInDTO>();
            return _storageRepository.AddStockIn(stockIn);
        }

        /// <summary>
        /// 显示全部仓库
        /// </summary>
        /// <param name="userId"></param> 
        /// <returns></returns>
        public List<WarehouseMemuItem> GetMemus()
        {
            return _storageRepository.GetMemus();
        }

        /// <summary>
        /// 入库显示+分页+查询
        /// </summary>
        /// <param name="productionOrderID"></param>
        /// <param name="stockInSubject"></param>
        /// <param name="stockInDate"></param>
        /// <returns></returns>
        public PageApiResut<StockIn> GetStockInPage(string? productionOrderID, string? stockInSubject, int page, int size)
        {
            try
            {
                return _storageRepository.GetStockInPage(productionOrderID, stockInSubject, page, size);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除入库信息
        /// </summary>
        /// <param name="stockInId"></param>
        /// <returns></returns>
        public APIResult<StockIn> DeleteData(int stockInId)
        {
            try
            {
                return _storageRepository.DeleteData(stockInId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 入库反填
        /// </summary>
        /// <param name="stockInId"></param>
        /// <returns></returns>
        public APIResult<StockInSelDTO> GetStockInSel(int stockInId)
        {
            try
            {
                return _storageRepository.GetStockInSel(stockInId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 入库修改
        /// </summary>
        /// <param name="stockInSel"></param>
        /// <returns></returns>
        public APIResult<StockInSelDTO> UpdateStockInSel(StockInSelDTO stockInSel)
        {
            try
            {
                return _storageRepository.UpdateStockInSel(stockInSel);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
